﻿using Device.API.Applcation.Command.UnitCommand;
using Device.Domain;
using Device.Infrstructre.Interface;
using MediatR;
using static Microsoft.EntityFrameworkCore.DbLoggerCategory;

namespace Device.API.Applcation.CommandHandlers.UnitCommandHandlers
{
    /// <summary>
    /// 修改单位中介者
    /// </summary>
    public class UpdUnitCommandHandlers : IRequestHandler<UpdUnitCommand, int>
    {
        private readonly IUnitRepository _unitRepository;
        public UpdUnitCommandHandlers(IUnitRepository unitRepository)
        {
            _unitRepository = unitRepository;
        }

        public async Task<int> Handle(UpdUnitCommand request, CancellationToken cancellationToken)
        {
            var res = new UnitModel() { AddName = request.AddName, AddTime = request.AddTime, UnitId = request.UnitId, UnitCode = request.UnitCode, UnitName = request.UnitName, Uremark = request.Uremark, Office_Id = request.Office_Id, User_Id = request.User_Id, UpdName = request.UpdName, UpdTime = request.UpdTime };
            return await _unitRepository.UpdateAsync(res);
        }
    }
}
